package com.plian.system.controller.fr.payrolladjustment;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.model.R;
import com.plian.system.service.fr.payrolladjustment.IPayrollTableConfigService;
import com.plian.system.service.fr.payrolladjustment.PayrollAdjustmentService;
import com.plian.system.vo.fr.report.ReportTableConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
@RequestMapping(value = "api/payrolladjustment")
public class PayrollAdjustmentController extends BaseController {
    @Autowired
    PayrollAdjustmentService payrollAdjustmentService;

    @Autowired
    IPayrollTableConfigService payrollTableConfigService;

    @PostMapping(value = "/savereport")
    public ObjResult savereport(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.savereport(pd);
    }

    @PostMapping(value = "/savezb")
    public ObjResult savezb(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.savezb(pd);
    }

    @PostMapping(value = "/listpage")
    public ListResult<PageData> listpage(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.listpage(pd);
    }

    @PostMapping(value = "/alist")
    public List<PageData> alist(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.alist(pd);
    }

    @PostMapping(value = "/valuelist")
    public ListResult<PageData> valuelist(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.valuelist(pd);
    }
    @PostMapping(value = "/findGsalaryValue")
    public ListResult<PageData> findGsalaryValue(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.findGsalaryValue(pd);
    }
    @PostMapping(value = "/detaillist")
    public ListResult<PageData> detaillist(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.detaillist(pd);
    }
    @PostMapping(value = "/uploadFile", produces = "application/json;charset=UTF-8")
    public ObjResult uploadFile(MultipartHttpServletRequest request) throws Exception {
        return payrollAdjustmentService.uploadFile(request);
    }

    @PostMapping(value = "/exportExcel", produces = "application/json;charset=UTF-8")
    public void exportExcel(@RequestBody PageData pd, HttpServletResponse response, OutputStream os) throws Exception {
        ArrayList<LinkedHashMap> list = (ArrayList<LinkedHashMap>) pd.get("data");
        payrollAdjustmentService.exportExcel(list, pd.getString("year"), response, os);
    }
//    @PostMapping(value = "/addvaluelist")
//    public ListResult<PageData> addvaluelist(@RequestBody PageData pd) throws Exception {
//        return payrollAdjustmentService.addvaluelist(pd);
//    }
//
//    @PostMapping(value = "/overvaluelist")
//    public ListResult<PageData> overvaluelist(@RequestBody PageData pd) throws Exception {
//        return payrollAdjustmentService.overvaluelist(pd);
//    }
//    @PostMapping(value = "/lastyear")
//    public ListResult<PageData> lastyear(@RequestBody PageData pd) throws Exception {
//        return payrollAdjustmentService.lastyear(pd);
//    }

    //    @PostMapping(value = "/editvalue")
//    public ObjResult editvalue(@RequestBody PageData pd) throws Exception {
//        return payrollAdjustmentService.editvalue(pd);
//    }
    @PostMapping(value = "/delete")
    public ObjResult delete(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.delete(pd);
    }

    @PostMapping(value = "/originReport")
    public ObjResult originReport(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.originReport(pd);
    }

    @PostMapping(value = "/saveChecked")
    public ObjResult saveChecked(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.saveChecked(pd);
    }

    @PostMapping(value = "/saveDiffChecked")
    public ObjResult saveDiffChecked(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.saveDiffChecked(pd);
    }

    @PostMapping(value = "/updatePassStatus")
    public ObjResult updatePassStatus(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.updatePassStatus(pd);
    }

    @PostMapping(value = "/findfm")
    public ObjResult findfm(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.findfm(pd);
    }

    @PostMapping(value = "/findChecked")
    public ObjResult findChecked(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.findChecked(pd);
    }

    @PostMapping(value = "/findDiffChecked")
    public ObjResult findDiffChecked(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.findDiffChecked(pd);
    }

    @PostMapping(value = "/ishavedata")
    public ObjResult ishavedata(@RequestBody PageData pd) throws Exception {
        return payrollAdjustmentService.ishavedata(pd);
    }

    @GetMapping(value = "/getTableConfig")
    public R<ReportTableConfigVO> getTableConfig(String year){
        R<ReportTableConfigVO> r = new R<>(CommonCode.SUCCESS);
        r.setPageData(payrollTableConfigService.getTableConfig(year));
        return r;
    }
}
